package com.lineage.server.model.Instance;

import java.util.HashMap;
import java.util.Map;

public class L1ItemPower {
  public static final Map<Integer, Integer> MR;
  
  public static final Map<Integer, Integer> MPR;
  
  public static final Map<Integer, Integer> SP;
  
  public static final Map<Integer, Integer> X2;
  
  public static final Map<Integer, Integer> HIT;
  
  public static final Map<Integer, Integer> HP;
  
  public static final Map<Integer, Integer> DMG_REDUCE;
  
  public static final Map<Integer, Integer> Attack;
  
  public static final Map<Integer, Integer> BowAttack;
  
  public static final Map<Integer, Integer> weightReductionByEnchant;
  
  public static final Map<Integer, Integer> MP = new HashMap<>();
  
  private final L1ItemInstance _itemInstance;
  
  static {
    MR = new HashMap<>();
    MPR = new HashMap<>();
    SP = new HashMap<>();
    X2 = new HashMap<>();
    HIT = new HashMap<>();
    HP = new HashMap<>();
    DMG_REDUCE = new HashMap<>();
    Attack = new HashMap<>();
    BowAttack = new HashMap<>();
    weightReductionByEnchant = new HashMap<>();
  }
  
  protected L1ItemPower(L1ItemInstance itemInstance) {
    this._itemInstance = itemInstance;
  }
  
  public static void load() {
    MR.put(Integer.valueOf(20011), new Integer(1));
    MR.put(Integer.valueOf(120011), new Integer(1));
    MR.put(Integer.valueOf(20110), new Integer(1));
    MR.put(Integer.valueOf(120110), new Integer(1));
    MR.put(Integer.valueOf(20056), new Integer(2));
    MR.put(Integer.valueOf(120056), new Integer(2));
    MR.put(Integer.valueOf(330005), new Integer(1));
    MR.put(Integer.valueOf(20117), new Integer(1));
    MR.put(Integer.valueOf(20049), new Integer(2));
    MR.put(Integer.valueOf(20050), new Integer(2));
    MR.put(Integer.valueOf(20078), new Integer(3));
    MR.put(Integer.valueOf(400019), new Integer(1));
    MR.put(Integer.valueOf(400023), new Integer(1));
    MR.put(Integer.valueOf(300427), new Integer(1));
    MR.put(Integer.valueOf(300433), new Integer(3));
    MR.put(Integer.valueOf(1300433), new Integer(3));
    MR.put(Integer.valueOf(310126), new Integer(2));
    MR.put(Integer.valueOf(70092), new Integer(2));
    MR.put(Integer.valueOf(70093), new Integer(2));
    MR.put(Integer.valueOf(401028), new Integer(1));
    MR.put(Integer.valueOf(401029), new Integer(1));
    MR.put(Integer.valueOf(401030), new Integer(1));
    MR.put(Integer.valueOf(401031), new Integer(1));
    MR.put(Integer.valueOf(400052), new Integer(2));
    weightReductionByEnchant.put(Integer.valueOf(310132), new Integer(60));
    MPR.put(Integer.valueOf(410163), new Integer(1));
    MPR.put(Integer.valueOf(1410163), new Integer(1));
    SP.put(Integer.valueOf(20107), new Integer(1));
    SP.put(Integer.valueOf(120107), new Integer(1));
    SP.put(Integer.valueOf(300431), new Integer(1));
    SP.put(Integer.valueOf(300433), new Integer(1));
    SP.put(Integer.valueOf(1300433), new Integer(1));
    SP.put(Integer.valueOf(300432), new Integer(1));
    SP.put(Integer.valueOf(1300432), new Integer(1));
    SP.put(Integer.valueOf(1300432), new Integer(1));
    SP.put(Integer.valueOf(124), new Integer(1));
    SP.put(Integer.valueOf(410158), new Integer(1));
    X2.put(Integer.valueOf(410188), new Integer(1));
    HIT.put(Integer.valueOf(400051), new Integer(1));
    HP.put(Integer.valueOf(300429), new Integer(25));
    Attack.put(Integer.valueOf(21106), new Integer(1));
    BowAttack.put(Integer.valueOf(21105), new Integer(1));
    DMG_REDUCE.put(Integer.valueOf(300430), new Integer(1));
    DMG_REDUCE.put(Integer.valueOf(120489), new Integer(1));
    DMG_REDUCE.put(Integer.valueOf(120490), new Integer(1));
    DMG_REDUCE.put(Integer.valueOf(120491), new Integer(1));
    DMG_REDUCE.put(Integer.valueOf(120492), new Integer(1));
    DMG_REDUCE.put(Integer.valueOf(310125), new Integer(1));
    MP.put(Integer.valueOf(21103), new Integer(10));
    HP.put(Integer.valueOf(21103), new Integer(20));
  }
  
  protected int getMr() {
    int mr = this._itemInstance.getItem().get_mdef();
    Integer integer = MR.get(Integer.valueOf(this._itemInstance.getItemId()));
    if (integer != null)
      mr += this._itemInstance.getEnchantLevel() * integer.intValue(); 
    return mr;
  }
  
  protected int getMpr() {
    int mpr = this._itemInstance.getItem().get_addmpr();
    Integer integer = MPR.get(Integer.valueOf(this._itemInstance.getItemId()));
    if (integer != null)
      mpr += this._itemInstance.getEnchantLevel() * integer.intValue(); 
    return mpr;
  }
  
  protected int getweightReductionByEnchant() {
    int Weight = this._itemInstance.getItem().getWeight();
    Integer integer = weightReductionByEnchant
      .get(Integer.valueOf(this._itemInstance.getItemId()));
    if (integer != null)
      if (this._itemInstance.getItemId() == 310132) {
        if (this._itemInstance.getEnchantLevel() >= 5)
          Weight += (this._itemInstance.getEnchantLevel() - 4) * integer.intValue(); 
      } else {
        Weight += this._itemInstance.getEnchantLevel() * integer.intValue();
      }  
    return Weight;
  }
  
  protected int getSp() {
    int sp = this._itemInstance.getItem().get_addsp();
    Integer integer = SP.get(Integer.valueOf(this._itemInstance.getItemId()));
    if (integer != null)
      if (this._itemInstance.getItemId() == 20107 || this._itemInstance.getItemId() == 120107) {
        if (this._itemInstance.getEnchantLevel() >= 3)
          sp += (this._itemInstance.getEnchantLevel() - 2) * integer.intValue(); 
      } else if (this._itemInstance.getItemId() == 300433) {
        if (this._itemInstance.getEnchantLevel() >= 7)
          sp += (this._itemInstance.getEnchantLevel() - 6) * integer.intValue(); 
      } else if (this._itemInstance.getItemId() == 300432 || this._itemInstance.getItemId() == 1300432) {
        if (this._itemInstance.getEnchantLevel() >= 8)
          sp += (this._itemInstance.getEnchantLevel() - 7) * integer.intValue(); 
      } else if (this._itemInstance.getItemId() == 124 || this._itemInstance.getItemId() == 410158) {
        if (this._itemInstance.getEnchantLevel() >= 7)
          sp += (this._itemInstance.getEnchantLevel() - 6) * integer.intValue(); 
      } else if (this._itemInstance.getItemId() == 300431) {
        int enchantlvl = this._itemInstance.getEnchantLevel();
        if (enchantlvl >= 5 && enchantlvl <= 6) {
          sp += integer.intValue();
        } else if (enchantlvl >= 7 && enchantlvl <= 8) {
          sp += integer.intValue() * 2;
        } else if (enchantlvl >= 9) {
          sp += integer.intValue() * 3;
        } 
      } else if (this._itemInstance.getItemId() == 1300433) {
        if (this._itemInstance.getEnchantLevel() >= 7)
          sp += (this._itemInstance.getEnchantLevel() - 6) * integer.intValue(); 
      } else {
        sp += this._itemInstance.getEnchantLevel() * integer.intValue();
      }  
    return sp;
  }
  
  protected int getDoubleDmgChance() {
    int x2 = this._itemInstance.getItem().getDoubleDmgChance();
    Integer integer = X2.get(Integer.valueOf(this._itemInstance.getItemId()));
    if (integer != null)
      x2 += this._itemInstance.getEnchantLevel() * integer.intValue(); 
    return x2;
  }
  
  protected int getHitModifierByArmor() {
    int hit = this._itemInstance.getItem().getHitModifierByArmor();
    Integer integer = HIT.get(Integer.valueOf(this._itemInstance.getItemId()));
    if (integer != null)
      if (this._itemInstance.getItemId() == 400051) {
        if (this._itemInstance.getEnchantLevel() >= 5)
          hit += (this._itemInstance.getEnchantLevel() - 4) * integer.intValue(); 
      } else {
        hit += this._itemInstance.getEnchantLevel() * integer.intValue();
      }  
    return hit;
  }
  
  protected int get_addhp() {
    int hp = this._itemInstance.getItem().get_addhp();
    Integer integer = HP.get(Integer.valueOf(this._itemInstance.getItemId()));
    if (integer != null)
      if (this._itemInstance.getItemId() == 300429) {
        int enchantlvl = this._itemInstance.getEnchantLevel();
        if (enchantlvl >= 5 && enchantlvl <= 6) {
          hp += integer.intValue();
        } else if (enchantlvl >= 7 && enchantlvl <= 8) {
          hp += integer.intValue() * 2;
        } else if (enchantlvl >= 9) {
          hp += integer.intValue() * 3;
        } 
      } else {
        hp += this._itemInstance.getEnchantLevel() * integer.intValue();
      }  
    return hp;
  }
  
  protected int get_addattack() {
    int attack = this._itemInstance.getItem().get_addattack();
    Integer integer = Attack.get(Integer.valueOf(this._itemInstance.getItemId()));
    if (integer != null)
      if (this._itemInstance.getItemId() == 21106) {
        int enchantlvl = this._itemInstance.getEnchantLevel();
        if (enchantlvl == 6) {
          attack += integer.intValue();
        } else if (enchantlvl == 7) {
          attack += integer.intValue() * 2;
        } else if (enchantlvl == 8) {
          attack += integer.intValue() * 3;
        } else if (enchantlvl >= 9) {
          attack += integer.intValue() * 4;
        } 
      } else {
        attack += this._itemInstance.getEnchantLevel() * integer.intValue();
      }  
    return attack;
  }
  
  protected int get_addbowattack() {
    int bowattack = this._itemInstance.getItem().get_addbowattack();
    Integer integer = BowAttack.get(Integer.valueOf(this._itemInstance.getItemId()));
    if (integer != null)
      if (this._itemInstance.getItemId() == 21105) {
        int enchantlvl = this._itemInstance.getEnchantLevel();
        if (enchantlvl == 6)
          bowattack += integer.intValue(); 
        if (enchantlvl == 7)
          bowattack += integer.intValue() * 2; 
        if (enchantlvl == 8)
          bowattack += integer.intValue() * 3; 
        if (enchantlvl >= 9)
          bowattack += integer.intValue() * 4; 
      } else {
        bowattack += this._itemInstance.getEnchantLevel() * integer.intValue();
      }  
    return bowattack;
  }
  
  protected int getDamageReduction() {
    int reduce = this._itemInstance.getItem().getDamageReduction();
    Integer integer = DMG_REDUCE.get(Integer.valueOf(this._itemInstance.getItemId()));
    if (integer != null && this._itemInstance.getItemId() == 300430) {
      int enchantlvl = this._itemInstance.getEnchantLevel();
      if (enchantlvl >= 5 && enchantlvl <= 6) {
        reduce += integer.intValue();
      } else if (enchantlvl >= 7 && enchantlvl <= 8) {
        reduce += integer.intValue() * 2;
      } else if (enchantlvl >= 9) {
        reduce += integer.intValue() * 3;
      } else if (this._itemInstance.getItemId() == 310125 || this._itemInstance.getItemId() == 1310125) {
        if (this._itemInstance.getEnchantLevel() >= 7)
          reduce += (this._itemInstance.getEnchantLevel() - 6) * integer.intValue(); 
      } else {
        reduce += this._itemInstance.getEnchantLevel() * integer.intValue();
      } 
    } 
    return reduce;
  }
  
  protected void GreaterAtEnchant(L1PcInstance owner, int randomELevel) {
    int level = this._itemInstance.getEnchantLevel();
    if (randomELevel == -1)
      level++; 
    switch (this._itemInstance.getItem().get_greater()) {
      case 0:
        switch (level) {
          case 1:
          case 2:
            owner.addMaxHp(randomELevel * 5);
            break;
          case 3:
          case 4:
            owner.addMaxHp(randomELevel * 10);
            break;
          case 5:
            owner.addMaxHp(randomELevel * 10);
            owner.add_up_hp_potion(randomELevel * 2);
            break;
          case 6:
            owner.add_up_hp_potion(randomELevel * 2);
            break;
          case 7:
            owner.addMaxHp(randomELevel * 10);
            owner.add_up_hp_potion(randomELevel * 2);
            break;
          case 8:
            owner.add_up_hp_potion(randomELevel * 2);
            break;
        } 
        break;
      case 1:
        switch (level) {
          case 1:
          case 2:
            owner.addMaxHp(randomELevel * 5);
            break;
          case 3:
          case 4:
            owner.addMaxHp(randomELevel * 10);
            break;
          case 5:
            owner.addMaxHp(randomELevel * 10);
            owner.addDmgModifierByArmor(randomELevel * 1);
            owner.addBowDmgModifierByArmor(randomELevel * 1);
            break;
          case 6:
            owner.addDmgModifierByArmor(randomELevel * 1);
            owner.addBowDmgModifierByArmor(randomELevel * 1);
            break;
          case 7:
            owner.addMaxHp(randomELevel * 10);
            owner.addDmgModifierByArmor(randomELevel * 1);
            owner.addBowDmgModifierByArmor(randomELevel * 1);
            break;
          case 8:
            owner.addDmgModifierByArmor(randomELevel * 1);
            owner.addBowDmgModifierByArmor(randomELevel * 1);
            break;
        } 
        break;
      case 2:
        switch (level) {
          case 1:
          case 2:
            owner.addMaxHp(randomELevel * 5);
            break;
          case 3:
          case 4:
            owner.addMaxHp(randomELevel * 10);
            break;
          case 5:
            owner.addMaxHp(randomELevel * 10);
            owner.addDamageReductionByArmor(randomELevel * 1);
            break;
          case 6:
            owner.addDamageReductionByArmor(randomELevel * 1);
            break;
          case 7:
            owner.addMaxHp(randomELevel * 10);
            owner.addDamageReductionByArmor(randomELevel * 1);
            break;
          case 8:
            owner.addDamageReductionByArmor(randomELevel * 1);
            break;
        } 
        break;
    } 
  }
  
  protected void greater(L1PcInstance owner, boolean equipment) {
    int level = this._itemInstance.getEnchantLevel();
    if (level <= 0)
      return; 
    if (equipment) {
      switch (this._itemInstance.getItem().get_greater()) {
        case 0:
          switch (level) {
            case 1:
              owner.addMaxHp(5);
              break;
            case 2:
              owner.addMaxHp(10);
              break;
            case 3:
              owner.addMaxHp(20);
              break;
            case 4:
              owner.addMaxHp(30);
              owner.addDmgModifierByArmor(1);
              owner.addBowDmgModifierByArmor(1);
              break;
            case 5:
              owner.addMaxHp(40);
              owner.add_up_hp_potion(4);
              owner.addDmgModifierByArmor(2);
              owner.addBowDmgModifierByArmor(2);
              owner.addDamageReductionByArmor(1);
              break;
            case 6:
              owner.addMaxHp(40);
              owner.add_up_hp_potion(6);
              owner.add_uhp_number(2);
              owner.addDmgModifierByArmor(4);
              owner.addBowDmgModifierByArmor(4);
              owner.addOriginalMagicHit(2);
              owner.addDamageReductionByArmor(2);
              break;
            case 7:
              owner.addMaxHp(50);
              owner.add_up_hp_potion(10);
              owner.add_uhp_number(4);
              owner.addDmgModifierByArmor(5);
              owner.addBowDmgModifierByArmor(5);
              owner.addOriginalMagicHit(4);
              owner.addPVPdmg(1);
              owner.addDamageReductionByArmor(3);
              break;
            case 8:
              owner.addMaxHp(50);
              owner.add_up_hp_potion(14);
              owner.add_uhp_number(6);
              owner.addDmgModifierByArmor(6);
              owner.addBowDmgModifierByArmor(6);
              owner.addOriginalMagicHit(8);
              owner.addPVPdmg(2);
              owner.addDamageReductionByArmor(3);
              break;
          } 
          break;
        case 1:
          switch (level) {
            case 1:
              owner.addMaxHp(5);
              break;
            case 2:
              owner.addMaxHp(10);
              break;
            case 3:
              owner.addMaxHp(20);
              break;
            case 4:
              owner.addMaxHp(30);
              owner.addDmgModifierByArmor(1);
              owner.addBowDmgModifierByArmor(1);
              owner.addDamageReductionByArmor(1);
              break;
            case 5:
              owner.addMaxHp(40);
              owner.addDmgModifierByArmor(3);
              owner.addBowDmgModifierByArmor(3);
              owner.addAc(-1);
              owner.addDamageReductionByArmor(3);
              break;
            case 6:
              owner.addMaxHp(40);
              owner.addDmgModifierByArmor(4);
              owner.addBowDmgModifierByArmor(4);
              owner.addSp(1);
              owner.addAc(-3);
              owner.addDamageReductionByArmor(3);
              break;
            case 7:
              owner.addMaxHp(50);
              owner.addDmgModifierByArmor(4);
              owner.addBowDmgModifierByArmor(4);
              owner.addSp(2);
              owner.addAc(-4);
              owner.addPVPdmg(1);
              owner.addDamageReductionByArmor(4);
              break;
            case 8:
              owner.addMaxHp(50);
              owner.addDmgModifierByArmor(5);
              owner.addBowDmgModifierByArmor(5);
              owner.addSp(4);
              owner.addAc(-5);
              owner.addPVPdmg(2);
              owner.addDamageReductionByArmor(5);
              break;
          } 
          break;
        case 2:
          switch (level) {
            case 1:
              owner.addMaxMp(5);
              break;
            case 2:
              owner.addMaxMp(10);
              break;
            case 3:
              owner.addMaxMp(20);
              break;
            case 4:
              owner.addMaxMp(30);
              owner.addDamageReductionByArmor(1);
              break;
            case 5:
              owner.addMaxMp(40);
              owner.addDamageReductionByArmor(2);
              owner.addMr(3);
              break;
            case 6:
              owner.addMaxMp(40);
              owner.addDamageReductionByArmor(4);
              owner.addMr(5);
              owner.addAc(-1);
              break;
            case 7:
              owner.addMaxMp(50);
              owner.addDamageReductionByArmor(4);
              owner.addMr(7);
              owner.addAc(-2);
              owner.addPVPdmgReduction(1);
              break;
            case 8:
              owner.addMaxMp(50);
              owner.addDamageReductionByArmor(5);
              owner.addMr(10);
              owner.addAc(-3);
              owner.addPVPdmgReduction(2);
              break;
          } 
          break;
      } 
    } else {
      switch (this._itemInstance.getItem().get_greater()) {
        case 0:
          switch (level) {
            case 1:
              owner.addMaxHp(-5);
              break;
            case 2:
              owner.addMaxHp(-10);
              break;
            case 3:
              owner.addMaxHp(-20);
              break;
            case 4:
              owner.addMaxHp(-30);
              owner.addDmgModifierByArmor(-1);
              owner.addBowDmgModifierByArmor(-1);
              break;
            case 5:
              owner.addMaxHp(-40);
              owner.add_up_hp_potion(-4);
              owner.addDmgModifierByArmor(-2);
              owner.addBowDmgModifierByArmor(-2);
              owner.addDamageReductionByArmor(-1);
              break;
            case 6:
              owner.addMaxHp(-40);
              owner.add_up_hp_potion(-6);
              owner.add_uhp_number(-2);
              owner.addDmgModifierByArmor(-4);
              owner.addBowDmgModifierByArmor(-4);
              owner.addOriginalMagicHit(-2);
              owner.addDamageReductionByArmor(-2);
              break;
            case 7:
              owner.addMaxHp(-50);
              owner.add_up_hp_potion(-10);
              owner.add_uhp_number(-4);
              owner.addDmgModifierByArmor(-5);
              owner.addBowDmgModifierByArmor(-5);
              owner.addOriginalMagicHit(-4);
              owner.addPVPdmg(-1);
              owner.addDamageReductionByArmor(-3);
              break;
            case 8:
              owner.addMaxHp(-50);
              owner.add_up_hp_potion(-14);
              owner.add_uhp_number(-6);
              owner.addDmgModifierByArmor(-6);
              owner.addBowDmgModifierByArmor(-6);
              owner.addOriginalMagicHit(-8);
              owner.addPVPdmg(-2);
              owner.addDamageReductionByArmor(-3);
              break;
          } 
          break;
        case 1:
          switch (level) {
            case 1:
              owner.addMaxHp(-5);
              break;
            case 2:
              owner.addMaxHp(-10);
              break;
            case 3:
              owner.addMaxHp(-20);
              break;
            case 4:
              owner.addMaxHp(-30);
              owner.addDmgModifierByArmor(-1);
              owner.addBowDmgModifierByArmor(-1);
              owner.addDamageReductionByArmor(-1);
              break;
            case 5:
              owner.addMaxHp(-40);
              owner.addDmgModifierByArmor(-3);
              owner.addBowDmgModifierByArmor(-3);
              owner.addAc(1);
              owner.addDamageReductionByArmor(-3);
              break;
            case 6:
              owner.addMaxHp(-40);
              owner.addDmgModifierByArmor(-4);
              owner.addBowDmgModifierByArmor(-4);
              owner.addSp(-1);
              owner.addAc(3);
              owner.addDamageReductionByArmor(-3);
              break;
            case 7:
              owner.addMaxHp(-50);
              owner.addDmgModifierByArmor(-4);
              owner.addBowDmgModifierByArmor(-4);
              owner.addSp(-2);
              owner.addAc(4);
              owner.addPVPdmg(-1);
              owner.addDamageReductionByArmor(-4);
              break;
            case 8:
              owner.addMaxHp(-50);
              owner.addDmgModifierByArmor(-5);
              owner.addBowDmgModifierByArmor(-5);
              owner.addSp(-4);
              owner.addAc(5);
              owner.addPVPdmg(-2);
              owner.addDamageReductionByArmor(-5);
              break;
          } 
          break;
        case 2:
          switch (level) {
            case 1:
              owner.addMaxMp(-5);
              break;
            case 2:
              owner.addMaxMp(-10);
              break;
            case 3:
              owner.addMaxMp(-20);
              break;
            case 4:
              owner.addMaxMp(-30);
              owner.addDamageReductionByArmor(-1);
              break;
            case 5:
              owner.addMaxMp(-40);
              owner.addDamageReductionByArmor(-2);
              owner.addMr(-3);
              break;
            case 6:
              owner.addMaxMp(-40);
              owner.addDamageReductionByArmor(-4);
              owner.addMr(-5);
              owner.addAc(1);
              break;
            case 7:
              owner.addMaxMp(-50);
              owner.addDamageReductionByArmor(-4);
              owner.addMr(-7);
              owner.addAc(2);
              owner.addPVPdmgReduction(-1);
              break;
            case 8:
              owner.addMaxMp(-50);
              owner.addDamageReductionByArmor(-5);
              owner.addMr(-10);
              owner.addAc(3);
              owner.addPVPdmgReduction(-2);
              break;
          } 
          break;
      } 
    } 
  }
}
